#ifndef		__GENE_FACTORY__IMP__
#define		__GENE_FACTORY__IMP__

#include "GeneFactoryIf.h"

class TCOM_API  GeneFactoryImp: public IGeneFactory
{
public:
	GeneFactoryImp();
	virtual ~GeneFactoryImp();

	//
	//	initialize the factory
	//
	virtual void	initialize();

	//
	//	gene create
	//	require an gene identifier : group id + id
	//	require an gene create dynamic data
	//
	virtual IGene*	create(IGeneCreateData& createData );

protected:
	class IGeneCreator
	{
	public:
		virtual ~IGeneCreator(){}

		virtual IGene* create() = 0;
	};


	template<class GENE>
	class GeneCreatorByTemplate : public IGeneCreator
	{
		virtual IGene* create()
		{
			return new GENE;
		}
	};


	typedef stdext::hash_map<int, IGeneCreator*>	GeneClass2Creator;


	template<class GENE>
	void	registerGene(const int& nCls)
	{
		GeneClass2Creator::iterator it = m_theCreators.find(nCls);
		if (it==m_theCreators.end())
		{
			m_theCreators.insert(make_pair(nCls, new GeneCreatorByTemplate<GENE>));
		}
		else
		{

		}
	}
private:
	GeneClass2Creator	m_theCreators;
};


#endif
